package Java复习;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class hello extends JFrame{
    public hello() throws HeadlessException {
        jm();
        scree();
        this.setVisible(true);
    }
    public void scree(){
        this.setTitle("联系人");
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
        this.pack();
    }
    public void jm(){
        JPanel jPanel1 = new JPanel();
        jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
        TextArea textArea1 = new TextArea("",7,40, TextArea.SCROLLBARS_VERTICAL_ONLY);
        jPanel1.add(textArea1);
        this.add(jPanel1,BorderLayout.NORTH);
        JPanel jPanel2 = new JPanel();
        jPanel2.setLayout(new GridLayout(2,1));
        JPanel jPanel3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
        JLabel jLabel1 = new JLabel("用户名");
        TextField field1 = new TextField(11);
        JLabel jLabel2 = new JLabel("电话");
        TextField field2 = new TextField(11);
        jPanel3.add(jLabel1);
        jPanel3.add(field1);
        jPanel3.add(jLabel2);
        jPanel3.add(field2);
        jPanel2.add(jPanel3);
        JPanel jPanel4 = new JPanel(new FlowLayout(FlowLayout.CENTER));
        TextField field3 = new TextField(20);
        JButton jButton1 = new JButton("显示");
        JButton jButton2 = new JButton("退出");
        jPanel4.add(field3);
        jPanel4.add(jButton1);
        jPanel4.add(jButton2);
        jPanel2.add(jPanel4);
        this.add(jPanel2);
        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                field3.setText("您按下了“显示”按钮");
                if ("".equals(field1.getText())||"".equals(field2.getText())){

                }else {
                    textArea1.setText("用户名: " + field1.getText()+"\n电话: " + field2.getText());
                }
            }
        });
        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               System.exit(0);
            }
        });
    }
}
public class 图形Num4 {
    public static void main(String[] args) {
        hello hello = new hello();
    }
}
